import java.util.Comparator;

public class Point implements Comparable<Point> {

    private final int x;
    private final int y;

    // compare points by slope to this point
    public final Comparator<Point> SLOPE_ORDER = new Comparator<Point>() {
        @Override
        public int compare(Point o1, Point o2) {
            return slopeTo(o1) < slopeTo(o2) ? -1 : slopeTo(o1) > slopeTo(o2) ? 1 : 0;
        }
    };

    // construct the point (x, y)
    public Point(int x, int y) {
        this.x = x;
        this.y = y;
    }

    // draw this point
    public void draw() {
        StdDraw.point(x, y);
//        StdDraw.circle(x, y, 200.0);
//        StdDraw.text(x + 1000, y + 1000, this.toString());
    }

    // draw the line segment from this point to that point
    public void drawTo(Point that) {
        StdDraw.line(this.x, this.y, that.x, that.y);
    }

    // string representation
    public String toString() {
        return "(" + x + ", " + y + ")";
    }

    // is this point lexicographically smaller than that point?
    @Override
    public int compareTo(Point that) {
        return this.y != that.y ? this.y - that.y : this.x - that.x;
    }

    // the slope between this point and that point
    public double slopeTo(Point that) {
        return that.x == this.x ? that.y == this.y ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY : that.y == this.y ? +0.0 : ((double)(that.y - this.y)) / (that.x - this.x);
    }

}
